home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / snpd1292.zip / SETIMETO.C < prev    next >
C/C++ Source or Header  |  1992-12-26  |  1KB  |  65 lines

  1. /*
  2. **  SETIMETO.C - Set the timestamp of one file to match another.
  3. **
  4. **  public domain demo by Bob Stout
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <dos.h>
  10. #include <io.h>
  11. #include <fcntl.h>
  12.  
  13. #ifdef __ZTC__
  14.  #define GETFTIME dos_getftime
  15.  #define SETFTIME dos_setftime
  16. #else
  17.  #define GETFTIME _dos_getftime
  18.  #define SETFTIME _dos_setftime
  19. #endif
  20.  
  21. int main(int argc, char *argv[])
  22. {
  23.       int fd0, fd1;
  24.  
  25. #ifdef __TURBOC__
  26.       struct ftime Ftime;
  27. #else
  28.       unsigned date, time;
  29. #endif
  30.  
  31.       if (3 > argc)
  32.       {
  33.             puts("Usage: SETIMETO old_filename new_filename");
  34.             return EXIT_FAILURE;
  35.       }
  36.  
  37.       if (-1 == (fd0 = open(argv[1], O_RDONLY)))
  38.       {
  39.             printf("Unable to open %s\n", argv[1]);
  40.             return EXIT_FAILURE;
  41.       }
  42.  
  43. #ifdef __TURBOC__                         /* Save the time/date         */
  44.       getftime(fd0, &Ftime);
  45. #else
  46.       GETFTIME(fd0, &date, &time);
  47. #endif
  48.  
  49.       if (-1 == (fd1 = open(argv[2], O_WRONLY)))
  50.       {
  51.             printf("Unable to open %s\n", argv[2]);
  52.             return EXIT_FAILURE;
  53.       }
  54.  
  55. #ifdef __TURBOC__                         /* Set the time/date          */
  56.       setftime(fd1, &Ftime);
  57. #else
  58.       SETFTIME(fd1, date, time);
  59. #endif
  60.  
  61.       close(fd0);
  62.       close(fd1);
  63.       return EXIT_SUCCESS;
  64. }
  65.